package com.example.netty.nio;

import java.nio.IntBuffer;

/**
 * buffer的基本使用
 */
public class BasicBuffer {
    public static void main(String[] args) {
        //声明buffer
        IntBuffer intBuffer = IntBuffer.allocate(10);

        //写入
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i);
        }
        //读写转换：读写的下标使用的是不同的变量，需要手动切换
        intBuffer.flip();
        //读取
        for (int i = 0; i < intBuffer.capacity(); i++) {
            System.out.println(intBuffer.get(i));
        }
    }
}
